import { Inject, Injectable } from '@nestjs/common'
import { CreateSiteDto } from './dto/create-site.dto'
import { UpdateSiteDto } from './dto/update-site.dto'
import { MongoRepository } from 'typeorm'
import { Site } from './site.mongo.entity'
import { ObjectId } from 'mongodb'

@Injectable()
export class SiteService {
  constructor(
    @Inject('SITE_REPOSITORY')
    private siteRepository: MongoRepository<Site>,
  ) {}
  create(createSiteDto: CreateSiteDto) {
    return this.siteRepository.save(createSiteDto)
  }

  findAll() {
    return this.siteRepository.find()
  }

  findOne(id: string) {
    return this.siteRepository.findOne({
      where: {
        _id: new ObjectId(id),
      },
    })
  }

  update(id: number, updateSiteDto: UpdateSiteDto) {
    return this.siteRepository.update(id, updateSiteDto)
  }

  remove(id: number) {
    return this.siteRepository.delete(id)
  }
}
